/*
 * @Author: Sa 
 * @Date: 2018-09-16 23:11:54 
 * @Last Modified by: mikey.zhaopeng
 * @Last Modified time: 2018-10-06 13:55:49
 */

import _axios from "@/utils/requestUtil";
import _urlConfig from "@/config/UserURLConfig";
import { get } from "http";
class User {
  /**
   * 1.快速注册
   */
  registerQuick(userinfo) {
    return _axios.request({
      url: _urlConfig.registerQuick,
      data: userinfo,
      method: "post"
    });
  }

  /**
   *2.用户注册
   */
  register(userinfo) {
    return _axios.request({
      url: _urlConfig.register,
      data: userinfo,
      method: "post"
    });
  }

   /**
   * 3.用户登录
   */
  login2(userInfo) {
    return _axios.request({
      url: _urlConfig.login,
      data: userInfo,
      method: "post"
    });
  }

  /**
   * 4.忘记密码：根据用户名获取问题
   */
  getQuestion(userInfo) {
    return _axios.request({
      url: _urlConfig.getQuestion,
      data: userInfo,
      method: "post"
    });
  }

  /**
   * 5.忘记密码：检查密码提示的答案
   */
  checkAnswer(userInfo) {
    return _axios.request({
      url: _urlConfig.checkAnswer,
      data: userInfo,
      method: "post"
    });
  }

  /**
   * 6.忘记密码： 重置密码
   */
  resetPassword(passwordInfo) {
    return _axios.request({
      url: _urlConfig.forgetResetPassword,
      data: passwordInfo,
      method: "post"
    });
  }

  /**
   *7. 获取用户信息
   */
  getUserInfomation(){
    return _axios.request({
      url: _urlConfig.getInfromation,
      data: null,
      method: "post"
    });
  }

  /**
   * 8.更新用户信息
   */
  getUpdateInfromation(updateInfo){
    return _axios.request({
      url: _urlConfig.updateInfromation,
      data: updateInfo,
      method: "post"
    });
  }

  /**
   * 9.校验用户名，电子邮箱、手机号的合法性
   */
  checkValid(type,value){
    return _axios.request({
      url: _urlConfig.checkValid+"?type="+type+"&value="+value,
    })
  }

  /**
   * 10.更新用户密码
   */
  updatePwd(passwordInfo){
    return _axios.request({
      url: _urlConfig.resetpwd,
      data: passwordInfo,
      method: "post"
    });
  }

  /**
   * 11.上传用户头像
   */
  uploadImages(file,userId,callBack, errorHandler){
    const url = _urlConfig.uploadImage
    let formData = new FormData()
    formData.append("files",file)
    formData.append("role","user")
    formData.append("roleId",userId)
    _axios.uploadFile(url,formData,callBack,errorHandler)
  }


  /**
   * 12.更新用户头像
   */
  updateImage(imageUrl){
    return _axios.request({
      url: _urlConfig.updateImage,
      data:{
        imageUrl: imageUrl
      },
      method: "post"
    });
  }

}
export default User;
